package com.gss.armory.form;

import java.util.Calendar;
import java.util.Date;

import org.springframework.format.annotation.DateTimeFormat;

import com.gss.common.util.ApplicationConstants;
import com.gss.common.util.ApplicationMaps;
import com.gss.common.util.ApplicationUtilities;

public class DocReports{

	private long docId;
	private String docName;
	private String docCode;
	
	private int docTypeId;
	private String dtName;
	
	private int docCategoryId;
	private String dcName;
	
	private int docSubCategoryId;
	private String dscName;
	
	private long docLocId;
	private String ldName;
	
	private long docDepttId;
	private String ddName;
	
	private String authSignId;
	private String authSign;
		
	@DateTimeFormat(pattern="dd-MM-yyyy")
	private Date docValidityStartDate;
	
	@DateTimeFormat(pattern="dd-MM-yyyy")
	private Date docValidityEndDate;
	
	private boolean renewable;
	
	private String docOwnerId;
	private String docOwnerName;
	
	public enum WorkflowStatus {
		PFS, PFR, PFA, PFRS, PFRR, PFRA
	}
	private WorkflowStatus wfStatus;
	
	private String reviewer;
	private String approver;
	
	private String strCreatedAuthor;
	private Date createdDate;
	private String strUpdatedAuthor;
	private Date updatedDate;
	
	private long diff;
	
	private long diffNE;
	private String docIssuingAuthority;
	private String docEnteredWith;
	
	private Integer docCompanyId;
	private String docCompanyName;
	
	
	public long getDocId() {
		return docId;
	}
	public String getDocName() {
		return docName;
	}
	public void setDocId(long docId) {
		this.docId = docId;
		
	}
	public void setDocName(String docName) {
		this.docName = docName;
		//this.docName = ApplicationMaps.DOCUMENT_ID_NAME_MAP.get(docId);
	}
	
	public int getDocTypeId() {
		return docTypeId;
	}
	public String getDtName() {
		return dtName;
	}
	public void setDocTypeId(int docTypeId) {
		this.docTypeId = docTypeId;
		setDtName(ApplicationMaps.DOCUMENT_TYPE_ID_NAME_MAP.get(docTypeId));
	}
	public void setDtName(String dtName) {
		//this.dtName = ApplicationMaps.DOCUMENT_TYPE_ID_NAME_MAP.get(docTypeId);
		this.dtName = dtName;
	}
	
	public int getDocCategoryId() {
		return docCategoryId;
	}
	public String getDcName() {
		return dcName;
	}
	public void setDocCategoryId(int docCategoryId) {
		this.docCategoryId = docCategoryId;
		setDcName(ApplicationMaps.DOCUMENT_CAT_ID_MAP.get(docCategoryId));
	}
	public void setDcName(String dcName) {
		this.dcName = dcName;
	}
	
	public int getDocSubCategoryId() {
		return docSubCategoryId;
	}
	public String getDscName() {
		return dscName;
	}
	public void setDocSubCategoryId(int docSubCategoryId) {
		this.docSubCategoryId = docSubCategoryId;
		setDscName(ApplicationMaps.DOCUMENT_SUB_CAT_ID_MAP.get(docSubCategoryId));
	}
	public void setDscName(String dscName) {
		//this.dscName = ApplicationMaps.DOCUMENT_SUB_CAT_ID_MAP.get(docSubCategoryId);
		this.dscName = dscName;
	}
	
	public long getDocLocId() {
		return docLocId;
	}
	public String getLdName() {
		return ldName;
	}
	
	public void setDocLocId(long docLocId) {
		this.docLocId = docLocId;
		setLdName(ApplicationMaps.LOCID_LOCNAME_MAP.get(docLocId));
	}
	public void setLdName(String ldName) {
		this.ldName = ldName;
	}
	
	public long getDocDepttId() {
		return docDepttId;
	}
	public String getDdName() {
		return ddName;
	}
	public void setDocDepttId(long docDepttId) {
		this.docDepttId = docDepttId;
		setDdName(ApplicationMaps.DEPTID_DEPTSNAME_MAP.get(docDepttId));
	}
	public void setDdName(String ddName) {
		//this.ddName = ApplicationMaps.DEPTID_DEPTSNAME_MAP.get(docDepttId);
		this.ddName = ddName;
	}
	
	public Date getDocValidityStartDate() {
		return docValidityStartDate;
	}
	public void setDocValidityStartDate(Date docValidityStartDate) {
		this.docValidityStartDate = docValidityStartDate;
	}
	
	public Date getDocValidityEndDate() {
		return docValidityEndDate;
	}
	public void setDocValidityEndDate(Date docValidityEndDate) {
		this.docValidityEndDate = docValidityEndDate;
	}
	
	public boolean isRenewable() {
		return renewable;
	}
	public void setRenewable(boolean renewable) {
		this.renewable = renewable;
	}
	
	public String getDocOwnerId() {
		return docOwnerId;
	}
	public String getDocOwnerName() {
		return docOwnerName;
	}
	public void setDocOwnerId(String docOwnerId) {
		this.docOwnerId = docOwnerId;
	}
	public void setDocOwnerName(String docOwnerName) {
		this.docOwnerName = docOwnerName;
	}
	
	public WorkflowStatus getWfStatus() {
		return wfStatus;
	}
	public void setWfStatus(WorkflowStatus wfStatus) {
		this.wfStatus = wfStatus;
	}
	
	public String getReviewer() {
		return reviewer;
	}
	public String getApprover() {
		return approver;
	}
	public void setReviewer(String reviewer) {
		this.reviewer = reviewer;
	}
	public void setApprover(String approver) {
		this.approver = approver;
	}
	
	public String getAuthSign() {
		return authSign;
	}
	public void setAuthSign(String authSign) {
		/*if(ApplicationUtilities.checkIfNullOrBlank(this.authSign)){
			this.authSign = authSign;
		}else{
			this.authSign = this.authSign + ", " + authSign;
		}*/
		this.authSign = authSign;
		
	}
	
	public String getAuthSignId() {
		return authSignId;
	}
	public void setAuthSignId(String authSignId) {
		
		if(!ApplicationUtilities.checkIfNullOrBlank(authSignId))
			{
			this.authSignId = authSignId;
			setAuthSign(ApplicationMaps.USERID_USERNAME_MAP.get(authSignId));
			}
		
	}
	public String getStrCreatedAuthor() {
		return strCreatedAuthor;
	}
	public Date getCreatedDate() {
		return createdDate;
	}
	public String getStrUpdatedAuthor() {
		return strUpdatedAuthor;
	}
	public Date getUpdatedDate() {
		return updatedDate;
	}
	public void setStrCreatedAuthor(String strCreatedAuthor) {
		this.strCreatedAuthor = strCreatedAuthor;
	}
	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}
	public void setStrUpdatedAuthor(String strUpdatedAuthor) {
		this.strUpdatedAuthor = strUpdatedAuthor;
	}
	public void setUpdatedDate(Date updatedDate) {
		this.updatedDate = updatedDate;
	}
	public String getDocCode() {
		return docCode;
	}
	public void setDocCode(String docCode) {
		this.docCode = docCode;
	}
	
	public long getDiffNE() {
		Date validityEndDate = this.docValidityEndDate;
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.DAY_OF_MONTH, 30);
		
		Date forDiff = calendar.getTime();
		
		this.diffNE =(30-((forDiff.getTime() - validityEndDate.getTime())/(24*60*60*1000)));
		
		return diffNE;
	}
	
	public void setDiffNE(long diffNE) {
		this.diffNE = diffNE;
	}
	
	public long getDiff() {
		Date validityEndDate = this.docValidityEndDate;
		Date currentDate = new Date();
		
		this.diff = (currentDate.getTime() - validityEndDate.getTime())/(24*60*60*1000);
		
		return diff;
	}
	public void setDiff(long diff) {
		this.diff = diff;
	}
		
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof DocReports)
		{
			DocReports docReports = (DocReports)obj;
			if(this.getDocId()!=0&&docReports.getDocId()!=0&&this.getDocId()==docReports.getDocId())
				return true;
			else if(this.getDocCode()!=null&&docReports.getDocCode()!=null&&this.getDocCode().equalsIgnoreCase(docReports.getDocCode()))
				return true;
			else
				return false;
		}
		else
			return false;
	}
	public String getDocIssuingAuthority() {
		return docIssuingAuthority;
	}
	public String getDocEnteredWith() {
		return docEnteredWith;
	}
	public void setDocIssuingAuthority(String docIssuingAuthority) {
		this.docIssuingAuthority = docIssuingAuthority;
	}
	public void setDocEnteredWith(String docEnteredWith) {
		this.docEnteredWith = docEnteredWith;
	}
	
	public Integer getDocCompanyId() {
		return docCompanyId;
	}
	public void setDocCompanyId(Integer docCompanyId) {
		this.docCompanyId = docCompanyId;
		if(ApplicationConstants.ALL_INT.intValue() != docCompanyId.intValue())
			setDocCompanyName(ApplicationMaps.COMPANYID_COMPANY_MAP.get(docCompanyId).getCdName());
	}
	public String getDocCompanyName() {
		return docCompanyName;
	}
	public void setDocCompanyName(String docCompanyName) {
		this.docCompanyName = docCompanyName;
	}
	
}
